package com.app.service.impl;

import com.app.dao.PopularRepository;
import com.app.entity.Popular;
import com.app.service.IPopularService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @autor xiaoyu.fang
 * @date 2019/10/11 15:21
 */
@Service
public class PopularServiceImpl implements IPopularService {

    @Autowired
    private PopularRepository popularRepository;

    @Override
    public void insert(Popular popular) {
        popular.setCreateAt(new Date());
        popularRepository.insert(popular);
    }

    @Override
    public void delete(ObjectId id) {
        popularRepository.deleteById(id);
    }

    @Override
    public List<Popular> query() {
        return popularRepository.findAll(new Sort(Sort.Direction.ASC, "createAt"));
    }
}
